package com.ruoyi.web.controller.activity;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activity.domain.ActNotice;
import com.ruoyi.activity.service.IActNoticeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动通知Controller
 * 
 * @author YZD
 * @date 2022-07-09
 */
@Controller
@RequestMapping("/activity/notice")
public class ActNoticeController extends BaseController
{
    private String prefix = "activity/notice";

    @Autowired
    private IActNoticeService actNoticeService;

    @RequiresPermissions("activity:notice:view")
    @GetMapping()
    public String notice()
    {
        return prefix + "/notice";
    }

    /**
     * 查询活动通知列表
     */
    @RequiresPermissions("activity:notice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActNotice actNotice)
    {
        startPage();
        List<ActNotice> list = actNoticeService.selectActNoticeList(actNotice);
        return getDataTable(list);
    }

    /**
     * 导出活动通知列表
     */
    @RequiresPermissions("activity:notice:export")
    @Log(title = "活动通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActNotice actNotice)
    {
        List<ActNotice> list = actNoticeService.selectActNoticeList(actNotice);
        ExcelUtil<ActNotice> util = new ExcelUtil<ActNotice>(ActNotice.class);
        return util.exportExcel(list, "活动通知数据");
    }

    /**
     * 新增活动通知
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动通知
     */
    @RequiresPermissions("activity:notice:add")
    @Log(title = "活动通知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActNotice actNotice)
    {
        actNotice.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(actNoticeService.insertActNotice(actNotice));
    }

    /**
     * 修改活动通知
     */
    @GetMapping("/edit/{noticeId}")
    public String edit(@PathVariable("noticeId") Long noticeId, ModelMap mmap)
    {
        ActNotice actNotice = actNoticeService.selectActNoticeById(noticeId);
        mmap.put("actNotice", actNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动通知
     */
    @RequiresPermissions("activity:notice:edit")
    @Log(title = "活动通知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActNotice actNotice)
    {
        actNotice.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(actNoticeService.updateActNotice(actNotice));
    }

    /**
     * 删除活动通知
     */
    @RequiresPermissions("activity:notice:remove")
    @Log(title = "活动通知", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actNoticeService.deleteActNoticeByIds(ids));
    }
}
